package fr.mywiki.view.web.struts.action.modeling;

import java.rmi.RemoteException;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import fr.mywiki.business.entry.meta.ModelException;
import fr.mywiki.view.web.struts.action.ListAction;
import fr.mywiki.view.web.struts.form.ListForm;
import fr.mywiki.view.web.struts.form.modeling.ModelsListForm;

public class ModelsListAction extends DispatchAction implements ListAction {
	/** Inits the list of models and displays it */
	public ActionForward display(ActionMapping mapping, ActionForm actionForm,
			HttpServletRequest request, HttpServletResponse response)
			throws SQLException, ModelException, RemoteException {
		ModelsListForm form = (ModelsListForm) actionForm;
		form.init();
		return mapping.findForward("display");
	}

	/** The user selected a model of the array. */
	public ActionForward selectElement(ActionMapping mapping,
			ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response) {
		ListForm form = (ListForm) actionForm;
		request.setAttribute(ELEMENT_ID, new Long(form.getIdElement()));
		return mapping.findForward("modifyModel");
	}

	/** Redirects to the model creation formular */
	public ActionForward createModel(ActionMapping mapping,
			ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response) {
		return mapping.findForward("createModel");
	}
}
